package com.superjson.showpro.shared.exception;


import com.superjson.showpro.shared.result.BaseResultCodeEnum;

import static com.superjson.showpro.shared.result.ResultCodeEnum.INTERNAL_ERROR;

/**
 * 业务性异常，自定义异常
 * @author baoya
 * @since 1.1.0
 */
public class GeneralBizException extends RuntimeException {

    private BaseResultCodeEnum resultCodeEnum = INTERNAL_ERROR;

    public GeneralBizException(BaseResultCodeEnum resultCodeEnum) {
        this.resultCodeEnum = resultCodeEnum;
    }

    public GeneralBizException(BaseResultCodeEnum resultCodeEnum, String msg) {
        super(msg);
        this.resultCodeEnum = resultCodeEnum;
    }

    /**
     * 只有发生没有归类的内部错误的时候，才可以使用这个方法，也就是默认了错误码为内部错误
     *
     * @param msg
     */
    public GeneralBizException(String msg) {
        super(msg);
    }

    public String getErrCode() {
        return resultCodeEnum.getCode();
    }

    public String getErrMsg() {
        return resultCodeEnum.getDesc();
    }

    public BaseResultCodeEnum getResultCodeEnum() {
        return resultCodeEnum;
    }
}
